package com.tianyang.yukuaifuzs.business.trade.adapter;

import android.annotation.SuppressLint;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tianyang.yukuaifuzs.R;
import com.tianyang.yukuaifuzs.business.trade.bean.TradeRecordOutput;
import com.tianyang.yukuaifuzs.utils.DateUtils;
import com.tianyang.yukuaifuzs.utils.VerifyUtil;

import java.util.ArrayList;

/**
 * Description：交易记录
 * Created by xyj on 2024/3/11
 */
public class TradeRecordAdapter extends BaseQuickAdapter<TradeRecordOutput, BaseViewHolder> {

    public TradeRecordAdapter() {
        super(R.layout.item_trade_record, new ArrayList<>());
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(@NonNull BaseViewHolder helper, TradeRecordOutput item) {
        if (item != null) {
            ImageView payTypeIv = helper.getView(R.id.payTypeIv);
            if (item.getPayType() == 2) {
                payTypeIv.setImageResource(R.drawable.ic_pay_wx);
            } else if (item.getPayType() == 3) {
                payTypeIv.setImageResource(R.drawable.ic_pay_ali);
            } else if (item.getPayType() == 1) {
                payTypeIv.setImageResource(R.drawable.ic_pay_syx);
            } else {
                payTypeIv.setImageResource(R.drawable.ic_pay_union);
            }
            TextView nameTv = helper.getView(R.id.nameTv);
            if (item.getUserPayOrderStatus() == 0) {
                nameTv.setText("交易成功");
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.black));
            } else if (item.getUserPayOrderStatus() == 1) {
                nameTv.setText("交易失败");
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_999999));
            } else if (item.getUserPayOrderStatus() == 2) {
                nameTv.setText("未支付");
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_999999));
            } else if (item.getUserPayOrderStatus() == 3) {
                nameTv.setText("交易中");
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_999999));
            } else if (item.getUserPayOrderStatus() == 4) {
                nameTv.setText("退款中");
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_999999));
            } else if (item.getUserPayOrderStatus() == 5) {
                nameTv.setText("退款成功");
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_999999));
            } else if (item.getUserPayOrderStatus() == 6) {
                nameTv.setText("退款失败");
                nameTv.setTextColor(ContextCompat.getColor(mContext, R.color.c_999999));
            } else {
                nameTv.setText("");
            }
            TextView timeTv = helper.getView(R.id.timeTv);
            if (item.getCreateTime() > 0) {
                timeTv.setText("时间：" + DateUtils.formatTime(item.getCreateTime()));
            } else {
                timeTv.setText("时间：" + DateUtils.getCurrentTime("yyyy-MM-dd"));
            }
            helper.setText(R.id.amountTv, VerifyUtil.decimalFormat(item.getAmount()));
        }
    }
}
